package cn.wolfcode.luowowo.common.util;

import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

public class MD5Util {
    /**
     * MD密码加密
     * @param str
     * @return
     */
    public static String EncoderByMd5(String str) {

        //判空操作
        AssertUtil.hasLength(str, "密码不能为空");

        MessageDigest md5 = null;
        String newStr = null;

        try {
            md5 = MessageDigest.getInstance("MD5");
            BASE64Encoder base64en = new BASE64Encoder();
            //加密后的字符串
            newStr = base64en.encode(md5.digest(str.getBytes("utf-8")));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return newStr;
    }
}
